using System;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Threading;

namespace OracleInternal.I18N
{
	internal class I18nStringResourceManager
	{
		private static ResourceManager s_rm;

		internal static Type resourceStringConstants;

		static I18nStringResourceManager()
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			Assembly assembly = null;
			Assembly[] array = assemblies;
			foreach (Assembly assembly2 in array)
			{
				if (assembly2.GetName().Name!.Equals("Oracle.ManagedDataAccess"))
				{
					assembly = assembly2;
					break;
				}
			}
			s_rm = new ResourceManager("Oracle.ManagedDataAccess.src.Client.Resources.Exception", assembly);
			resourceStringConstants = assembly.GetType("Oracle.ManagedDataAccess.Client.ResourceStringConstants");
		}

		private I18nStringResourceManager()
		{
		}

		internal static ResourceManager Instance()
		{
			return s_rm;
		}

		internal static string GetErrorMesg(string errorcode, params string[] args)
		{
			string text = null;
			CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
			int value = (int)resourceStringConstants.GetField(errorcode, BindingFlags.Static | BindingFlags.NonPublic)!.GetValue(resourceStringConstants);
			string @string = Instance().GetString(Convert.ToString(value), currentCulture);
			if (@string != null)
			{
				return string.Format(@string, args);
			}
			return string.Empty;
		}

		internal static string GetErrorMesgWithErrCode(string errorcode, params string[] args)
		{
			string errorMesg = GetErrorMesg(errorcode, args);
			return $"ORA-{errorcode}: {errorMesg}";
		}
	}
}
